
/* This do file provides the code to generate Figure A3.1 in Appendix 3. */

global dataDir "~/Dropbox/Party_Interactions_Perceptions/PSRM Submission/Replication Files"
use "$dataDir/replication_data.dta", clear



set more off
foreach i of numlist 1 2{

replace dyad_name`i'="AfD" if dyad_name`i'=="afd"
replace dyad_name`i'="Alt" if dyad_name`i'=="alt"
replace dyad_name`i'="BQ" if dyad_name`i'=="bq"
replace dyad_name`i'="CDU" if dyad_name`i'=="cdu"
replace dyad_name`i'="Cons" if dyad_name`i'=="cons"
replace dyad_name`i'="KF" if dyad_name`i'=="cpp"
replace dyad_name`i'="DF" if dyad_name`i'=="dpp"
replace dyad_name`i'="Enh" if dyad_name`i'=="enh"
replace dyad_name`i'="FDP" if dyad_name`i'=="fdp"
replace dyad_name`i'="Lab" if dyad_name`i'=="lab"
replace dyad_name`i'="Lib" if dyad_name`i'=="lib"
replace dyad_name`i'="LibDem" if dyad_name`i'=="libdem"
replace dyad_name`i'="Linke" if dyad_name`i'=="linke"
replace dyad_name`i'="NDP" if dyad_name`i'=="ndp"
replace dyad_name`i'="NB" if dyad_name`i'=="new"
replace dyad_name`i'="RadVen" if dyad_name`i'=="rad"
replace dyad_name`i'="SDP" if dyad_name`i'=="sdp"
replace dyad_name`i'="SNP" if dyad_name`i'=="snp"
replace dyad_name`i'="SPD" if dyad_name`i'=="spd"
replace dyad_name`i'="SF" if dyad_name`i'=="spp"
replace dyad_name`i'="UKIP" if dyad_name`i'=="ukip"
replace dyad_name`i'="Ven" if dyad_name`i'=="ven"
replace dyad_name`i'="Green" if dyad_name`i'=="green"


}

capture drop dyadname
egen dyadname=concat(dyad_name1 dyad_name2), punct("-")


capture drop countryyear
egen countryyear=concat(country year)


 /* Canada 2017 */
 
 set more off

local figure=1
levelsof dyadname if countryyear=="Canada2017" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="Canada2017" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="Canada2017" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(27 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="Canada2017", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="Canada2017" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)
 
 
graph combine fig9 fig10 fig6 fig5 fig8 fig3 fig2 fig4 fig7 ///
fig1 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(2) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(Canada 2017)  
 
 graph export "$dataDir/figA3_1(part 1).pdf", replace

 
 /* Canada 2019 */
 
 set more off

local figure=1
levelsof dyadname if countryyear=="Canada2019" & coop!=., local(levels) 
 foreach l of local levels {
 
sum coop if dyadname=="`l'" & countryyear=="Canada2019" & coop!=.

local ll2 : di %3.2f r(mean)

 
twoway histogram coop if dyadname=="`l'" & countryyear=="Canada2019" ///
 & coop!=., ///
 discrete percent xtitle("") ytitle("") color(gray) xline(`ll2') ///
 text(27 `ll2' "`ll2'") title("`l'") graphregion(margin(0 0 0 0)) plotregion(margin(0 0 0 0)) ///
 name(`ctryyear'fig`figure', replace) yscale(r(0 30)) nodraw
 
 local figure=`figure'+1
 
 }
 
 
 
 capture drop partiesname
 gen partiesname=""
 
  capture drop avg
 gen avg=.
 
 local row=1
 levelsof dyadname if countryyear=="Canada2019", local(levels) 
 foreach l of local levels {
 sum coop if dyadname=="`l'" & countryyear=="Canada2019" & coop!=.
replace avg=r(mean) in `row'
  replace partiesname="`l'" in `row'
  local row=`row'+1

 }
 capture drop groupid
 egen groupid=group(partiesname)
 
graph combine fig9 fig6 fig10 fig5 fig2 fig7 fig8 fig3 fig1 ///
fig4 , ///
 l1(% of Respondents) b1(Perceived Cooperation Scores) rows(2) ///
 note("Dashed line indicates the average cooperation score",size(vsmall)) ///
 ycommon scale(1.15) title(Canada 2019) 
 

 graph export "$dataDir/figA3_1(part 2).pdf", replace
